package thread.dead_lock;

public class DeadLockTest {
    public static void main(String[] args) {
        Object projectLock = new Object();
        Object songLock = new Object();
        Thread t1 = new Thread(()  ->{
            synchronized (projectLock){
                System.out.println("舒服廖，我开始写项目");
                synchronized (songLock) {
                    System.out.println("铭哥先唱个曲，我再去写项目");
                    try {
                        Thread.sleep(300);
                    }catch (InterruptedException e){
                        throw  new RuntimeException(e);
                    }
            }
//            synchronized (projectLock){
//                System.out.println("舒服廖，我开始写项目");
//            }
            }
        },"阿龙");
        Thread t2 = new Thread(()  ->{
            synchronized (projectLock){
                System.out.println("大家先把项目写完，我再唱歌曲儿~");
                try{
                    Thread.sleep(300);
                }catch (InterruptedException e){
                    throw  new RuntimeException();
                }
                synchronized (songLock){
                    System.out.println("大家写完项目了，我给大家来一首**");
                }
            }
        },"铭哥");
        t1.start();
        t2.start();
    }
}
